package com.powerunion.datacollection.config;

import java.util.Properties;
import java.io.IOException;
import java.io.InputStream;

import com.powerunion.datacollection.transaction.Transaction;



/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ConfigUtil {
    private Properties properties = null;
    private static ConfigUtil instance = null;

    private ConfigUtil() {
        this.properties = new Properties();
        InputStream in = this.getClass().getClassLoader().getResourceAsStream(
                "com/powerunion/datacollection/config/config.properties");
        try {
            this.properties.load(in);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

    public static ConfigUtil getInstance(){
        if(instance == null)
            instance = new ConfigUtil();
        return instance;
    }

    public String getParameter(String key){
        return this.properties.getProperty(key);
    }
    
    public static Transaction getTransaction()throws Exception{
        String className = ConfigUtil.getInstance().getParameter("transaction");
        return (Transaction)Class.forName(className).newInstance();
    }
    
}
